package uk.ac.ebi.bioinvindex.utils.mock;

import uk.ac.ebi.bioinvindex.dao.BIIDAOException;
import uk.ac.ebi.bioinvindex.model.impl.StudyImpl;
import uk.ac.ebi.bioinvindex.model.impl.term.DesignImpl;
import uk.ac.ebi.bioinvindex.model.impl.term.FreeTextTermImpl;
import uk.ac.ebi.bioinvindex.model.impl.term.OntologyEntryImpl;


/**
 * User: Nataliya Sklyar (nsklyar@ebi.ac.uk)
 * Date: Sep 14, 2007
 */
public class MockBIIFactory {

	public static StudyImpl buildStudy(String acc, String title) {
		StudyImpl study = new StudyImpl(title);
		study.setAcc(acc);
		study.setDescription("Very long mock Study description");
		study.setObjective("Very important Study objective");

		return study;
	}

	public static <T extends FreeTextTermImpl> T buildTerm(Class<T> termClass, String name) {
		if (termClass == null) {
			throw new IllegalArgumentException("termClass cannot be null!");
		}

		T term;

		try {
			term = termClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BIIDAOException("Cannot instantiate class " + termClass, e);
		}

		term.setValue(name);
		return term;
	}


	public static <T extends OntologyEntryImpl> T buildOntologyEntry(Class<T> termClass, String name, String acc) {
		if (termClass == null) {
			throw new IllegalArgumentException("termClass cannot be null!");
		}

		T term;

		try {
			term = termClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BIIDAOException("Cannot instantiate class " + termClass, e);
		}

		term.setName(name);
		term.setAcc(acc);

		return term;
	}


	public static void main(String[] args) {
		DesignImpl design = MockBIIFactory.buildTerm(DesignImpl.class, "Design");
		System.out.println("design = " + design);


	}
}
